function endToLoad (caller) {
  // 初始化
  let loadingDiv = generateDiv(); // 生成刷新层
  let oldScrollHeight, oldScrollTop, screenHeight, scrollTop, scrollHeight, firstToEnd = true;

  document.addEventListener('touchstart', () => {
  });
  if (document.eventList === undefined) document.eventList = {};

  // 首次触底绑定事件
  function toOld () {
    $('body').scrollTop(oldScrollTop - 1);
    controlRefreshDiv(loadingDiv, false)
    firstToEnd = true;
  }

  // 二次触底绑定事件
  function loadData () {
    document.removeEventListener('touchend', loadData);
    delete document.eventList["touchend"]
    loadingDiv.html('加载中...')
    // 异步加载完成时处理
    caller(loaded, noData)

    // 加载成功执行函数
    function loaded() {
      setTimeout(() => {
        firstToEnd = true;
        scrollHeight = document.body.scrollHeight;
        oldScrollHeight = scrollHeight;
        controlRefreshDiv(loadingDiv, false)
        loadingDiv.html('↓ 下拉刷新');
      })
    }

    // 加载失败或者没有数据执行函数
    function noData () {
      loadingDiv.html('已经拉到底啦');
      setTimeout(() => {
        toOld()
      }, 500)
    }
  }

  document.addEventListener('scroll', () => {
    screenHeight = document.body.clientHeight;
    scrollTop = document.body.scrollTop
    scrollHeight = document.body.scrollHeight;

    // 触底
    if (scrollTop + screenHeight >= scrollHeight) {
      if (firstToEnd) {
        //首次触底=>呈现下拉刷新提示层
        oldScrollHeight = scrollHeight;
        oldScrollTop = scrollTop;
        controlRefreshDiv(loadingDiv, true);
        loadingDiv.html('↓ 下拉刷新');
        firstToEnd = false; //是否首次触底
      } else {
        // 二次触底=>加载数据
        loadingDiv.html('↑ 松开刷新');
        // 删除首次触底绑定的回滚事件(未二次触底时滚动回底部-1)
        document.removeEventListener('touchend', toOld);
        delete document.eventList['touchend']
        // 从新绑定二次触底的新事件(释放点击时加载数据)
        if (!('touchend' in document.eventList)) {
          document.addEventListener('touchend', loadData);
          document.eventList['touchend'] = true;
        }
      }
    } else if (scrollTop + screenHeight >= oldScrollHeight && scrollTop + screenHeight < scrollHeight) {
      // 首次触底后依然持续下拉，但未二次触底,绑定回事件
      if (!('touchend' in document.eventList)) {
        document.addEventListener('touchend', toOld);
        document.eventList['touchend'] = true;
      }
    } else if (scrollTop + screenHeight < oldScrollHeight) {
      // 首次触底后未二次触底，清除回滚绑定事件
      document.removeEventListener('touchend', toOld);
      delete document.eventList['touchend']
      firstToEnd = true;
    }
  })

  // 生成刷新div
  function generateDiv () {
    let css = {
      width: '100%',
      height: '0.9rem',
      backgroundColor: '#fff',
      color: '#444',
      fontSize: '.32rem',
      textAlign: 'center',
      display: 'none',
      marginBottom: '.98rem'
    },
    div = $('<div>↓ 下拉刷新</div>');
    return div.css(css)
  }

  // 控制刷新div
  function controlRefreshDiv (div, isEnd) {
    if (isEnd) {
      $(body).append(div)
      div.css('display', 'block')
    } else {
      div.remove()
    }
  }

  return {
    hide() {
      controlRefreshDiv(loadingDiv, false)
    }
  }
}
